<template>
	<view class="container bg-fff">
		
		<view class="item flex-space-between">
			<view class="item-label">发票抬头</view>
			<view class="item-value" @click="show = true">
				<input type="text" v-model="form.invoice_name" placeholder="请选择发票抬头" disabled />
			</view>
		</view>
		
		<b-u-button-theme-plain width="100%" height="90rpx" @click="jump('/pages/mine/invoice/info')">添加新抬头</b-u-button-theme-plain>
		
		<view class="" style="margin-top: 100rpx;"></view>
		
		<b-u-button-theme width="100%" height="90rpx" @click="send">提交</b-u-button-theme>
		
		
		<u-select v-model="show" :list="list" value-name="id" label-name="title" @confirm="confirm"></u-select>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {},
				list: [],
				show: false,
			}
		},
		onLoad(options) {
			this.form.order_id = options.order_id;
			this.form.shop_supplier_id = options.shop_supplier_id;
		},
		onShow() {
			this.getHttp();
		},
		methods: {
			send() {
				if(uni.$u.test.isEmpty(this.form.invoice_id)) {
					uni.showToast({
						title: "请选择发票抬头",
						icon: "none"
					})
					return  ;
				}
				uni.$u.api.postInvoiceOrder(this.form).then(res => {
					uni.showModal({
						title: '提示',
						content: '提交成功',
						showCancel: false,
						success: (res) => {
							if (res.confirm) {
								uni.navigateBack();
								// console.log('用户点击确定');
							} else if (res.cancel) {
								// console.log('用户点击取消');
							}
						}
					});
				})

			},
			confirm(e) {
				this.form.invoice_id = e[0].value;
				this.form.invoice_name = e[0].label;
			},
			jump(url) {
				uni.navigateTo({
					url: url
				})
			},
			getInvoice() {
				uni.$u.api.getInvoice(this.pageForm).then(res => {
					this.list = res;
				})
			},
			getHttp() {
				this.getInvoice();
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 30rpx;
		
		.item {
			margin-bottom: 24rpx;
			
			.item-label {
				font-size: 28rpx;
				color: #333333;
			}
			
			.item-value {
				
				input {
					width: 438rpx;
					background: #F6F6F6;
					padding: 24rpx;
					border-radius: 16rpx;
				}
			}
		}
	}
</style>
